package com.zcs.thread.communication;

/**
 *
 * 线程通信相关
 * @author zcs
 * @since 2023/4/24
 */
public class Join {

    public static void main(String[] args) {
        new ThreadTest().threadTest();
        System.out.println("如果不加join方法，我会先被打出来，加了就不一样了");
    }


    static class ThreadTest {
        public void threadTest() {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        System.out.println("我是子线程，我先睡一秒");
                        Thread.sleep(1000);
                        System.out.println("我是子线程，我睡完了一秒");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
            try {
                thread.start();
                thread.join();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
